const {DataTypes} = require("sequelize");

const seq = require("../db/seq");
const User = require("./user.model");
const Category = require("./category.model");
const Information = require("./information.model");

// 创建模型(Model zd_user -> 表 zd_users)
const Collect = seq.define(
    "collect",
    {
        // id 会被sequelize自动创建, 管理
        info_id: {
            type: DataTypes.INTEGER,
            allowNull: true,
            comment: "资讯id",
        },
        cat_id: {
            type: DataTypes.INTEGER,
            allowNull: true,
            comment: "项目id",
        },
        user_id: {
            type: DataTypes.INTEGER,
            allowNull: false,
            comment: "用户id",
        }
    },
    {
        paranoid: true,
    }
);

Collect.belongsTo(User, {
    foreignKey: "user_id",
    as: "user_info",
});
Collect.belongsTo(Information, {
    foreignKey: "info_id",
    as: "information_info",
});
Collect.belongsTo(Category, {
    foreignKey: "cat_id",
    as: "category_info",
});
// 强制同步数据库(创建数据表)
// Collect.sync({ force: true });

module.exports = Collect;
